package cn.wolfcode.crm.qo;

import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class PageResult<T> {
    private Integer currentPage; //当前页
    private Integer pageSize;  //每页显示条数
    //sql查询出来的数据
    private List<?> list; //结果集
    private Integer totalCount; //结果总数
    //计算出来的数据
    private Integer prevPage;  //上一页
    private Integer nextPage;  //下一页
    private Integer totalPage;  //总页数

    //当总条数为0时使用
    public PageResult(Integer pageSize){
        this(1, pageSize, 0, Collections.EMPTY_LIST);
    }

    public PageResult(Integer currentPage, Integer pageSize, Integer totalCount, List<?> list) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.totalCount = totalCount;

        //计算
        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage > 1 ? currentPage - 1 : 1;
        this.nextPage = currentPage < totalPage ? currentPage + 1 : totalPage;
    }
}
